package com.thinkfit.jy.utils;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.graphics.PixelFormat;
import android.media.AudioManager;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.WindowManager;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.blankj.utilcode.util.AppUtils;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.listener.OnItemClickListener;
import com.common.lib.bean.ApplicationBean;
import com.common.lib.constant.EventBusEvent;
import com.common.lib.manager.DataManager;
import com.common.lib.utils.BaseUtils;
import com.thinkfit.jy.R;
import com.thinkfit.jy.activity.FreeMovementNewActivity;
import com.thinkfit.jy.activity.MainActivity;
import com.thinkfit.jy.activity.SettingNewActivity;
import com.thinkfit.jy.adapter.AppHomeAdapter;
import com.thinkfit.jy.dialog.AppPopupWindow;
import com.thinkfit.jy.serialport.SerialPortManager;
import com.thinkfit.jy.serialport.SportType;
import com.thinkfit.jy.view.LeftSlopSetView;
import com.thinkfit.jy.view.RightSpeedSetView;

import org.greenrobot.eventbus.EventBus;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.concurrent.TimeUnit;

import io.reactivex.Observable;
import io.reactivex.ObservableEmitter;
import io.reactivex.ObservableOnSubscribe;
import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;

/**
 * 开始运动与调节速度、坡度、阻力（可在第三方应用上显示）
 */
public class SportsStatusBarViewUtils implements View.OnClickListener, View.OnTouchListener, View.OnLongClickListener {

    private static final String TAG = "SportsStatusBarViewUtils ----------------->";
    private static SportsStatusBarViewUtils sportsStatusBarViewUtils;
    WindowManager windowManager;
    Context mContext;
    private final int pageSize = 8;
    private int currentIndex;
    boolean isFist = true;
    boolean isShowApp = false;
    boolean isRun = false;
    boolean isLongClick = false;
    View inflate;
    ImageView ivSet,ivBack,ivVolume,ivLuminance,ivHome,ivHome1,ivApk,ivApk1,ivSpeedReduce,ivSpeedAdd,ivSlopAdd,ivSlopReduce;
    TextView tvStart,tvSetGoal,tvStop,tvPause,tvSpeedTip,tvSpeed,tvUnit,tvSlop,tvSlopTip;
    ConstraintLayout clRunning,clBottom,clHome;
    RecyclerView rvApp;
    private int mMaxVolume;
    AppHomeAdapter appHomeAdapter;
    int mType;
    int mNum;
    float posX,posY,curPosX,curPosY;
    private AudioManager mAudioManager;

    public static SportsStatusBarViewUtils getInstance(){
        if(sportsStatusBarViewUtils == null){
            sportsStatusBarViewUtils = new SportsStatusBarViewUtils();
        }
        return sportsStatusBarViewUtils;
    }


    public void initView(Context context){
        mContext = context;
        if(windowManager == null){
            windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
        }

        int language = DataManager.Companion.getInstance().getLanguage();
        BaseUtils.StaticParams.changeAppLanguage(context, language);

        if(inflate == null){
            if(DataManager.Companion.getInstance().getMainStyle() == ThemeUtils.THEME_DRAGON_BOAT_FESTIVAL){
                inflate = LayoutInflater.from(context).inflate(R.layout.item_sports_status_bar_dw, null);
            }else if(DataManager.Companion.getInstance().getMainStyle() == ThemeUtils.THEME_FIRE_PROTECTION){
                inflate = LayoutInflater.from(context).inflate(R.layout.item_sports_status_bar_xf, null);
            }else if(DataManager.Companion.getInstance().getMainStyle() == ThemeUtils.THEME_PINK){
                inflate = LayoutInflater.from(context).inflate(R.layout.item_sports_status_bar_pink, null);
            }else if(DataManager.Companion.getInstance().getMainStyle() == ThemeUtils.THEME_LANDSCAPE){
                inflate = LayoutInflater.from(context).inflate(R.layout.item_sports_status_bar_scenery, null);
            }else {
                inflate = LayoutInflater.from(context).inflate(R.layout.item_sports_status_bar, null);
            }
        }
        clHome = inflate.findViewById(R.id.cl_home);
        rvApp = inflate.findViewById(R.id.rv_app);
        ivSet = inflate.findViewById(R.id.iv_set);
        ivBack = inflate.findViewById(R.id.iv_back);
        ivVolume = inflate.findViewById(R.id.iv_volume);
        ivLuminance = inflate.findViewById(R.id.iv_luminance);
        tvStart = inflate.findViewById(R.id.tv_start);
        tvStop = inflate.findViewById(R.id.tv_stop);
        tvPause = inflate.findViewById(R.id.tv_pause);
        tvSpeed = inflate.findViewById(R.id.tv_speed);
        tvSpeedTip = inflate.findViewById(R.id.tv_speed_tip);
        tvUnit = inflate.findViewById(R.id.tv_unit);
        tvSlop = inflate.findViewById(R.id.tv_slop);
        tvSlopTip = inflate.findViewById(R.id.tv_slop_tip);
        tvSetGoal = inflate.findViewById(R.id.tv_set_goal);
        ivHome = inflate.findViewById(R.id.iv_home);
        ivHome1 = inflate.findViewById(R.id.iv_home1);
        ivApk = inflate.findViewById(R.id.iv_apk);
        ivApk1 = inflate.findViewById(R.id.iv_apk1);
        clRunning = inflate.findViewById(R.id.clRunning);
        clBottom = inflate.findViewById(R.id.clBottom);
        ivSpeedReduce = inflate.findViewById(R.id.iv_speed_reduce);
        ivSpeedAdd = inflate.findViewById(R.id.iv_speed_add);
        ivSlopAdd = inflate.findViewById(R.id.iv_slop_add);
        ivSlopReduce = inflate.findViewById(R.id.iv_slop_reduce);

        LinearLayoutManager layoutManager = new LinearLayoutManager(mContext);
        layoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
        rvApp.setLayoutManager(layoutManager);
        if(appHomeAdapter == null){
            appHomeAdapter = new AppHomeAdapter(mContext);
            appHomeAdapter.setOnItemClickListener(new OnItemClickListener() {
                @Override
                public void onItemClick(@NonNull BaseQuickAdapter<?, ?> adapter, @NonNull View view, int position) {
                    ApplicationBean currentRunningApp = (ApplicationBean) adapter.getItem(position);
                    if(SystemUtils.isAppRunning(mContext,currentRunningApp.getAppid())){
                        System.out.println("ddddddddddddddddddddddd   apkssss");
//                        SystemUtils.setTopApp(mContext,currentRunningApp.getAppid());
                        PackageManager packageManager = mContext.getPackageManager();
                        Intent intent = packageManager.getLaunchIntentForPackage(currentRunningApp.getAppid());
                        if (intent != null) {
                            mContext.startActivity(intent);
                        }
                    }else {
                        RunningAppUtils.getInstance().init(mContext);
                        ArrayList<ApplicationBean> currentRunningApps = RunningAppUtils.getInstance().getCurrentRunningApp();
                        if(currentRunningApps.size()>=3){
                            DialogCloseApkViewUtils.getInstance().initView(mContext,currentRunningApp.getAppid());
                        }else {
                            PackageManager packageManager = mContext.getPackageManager();
                            Intent intent = packageManager.getLaunchIntentForPackage(currentRunningApp.getAppid());
                            if (intent != null) {
                                mContext.startActivity(intent);
                            }
                        }

//                        boolean isOpen = RunningAppUtils.getInstance().isOpen(currentRunningApp.getAppid());
//                        System.out.println("aaaaaaaaaaaaaaaaaaaaaaaaa   isOpen : "+isOpen);
//                        if(!isOpen){//是否已经打开
//                            if(currentRunningApps.size()>=3){
//                                DialogCloseApkViewUtils.getInstance().initView(mContext,currentRunningApp.getAppid());
//                            }else {
//                                PackageManager packageManager = mContext.getPackageManager();
//                                Intent intent = packageManager.getLaunchIntentForPackage(currentRunningApp.getAppid());
//                                if (intent != null) {
//                                    mContext.startActivity(intent);
//                                }
//                            }
//                        }else {
//                            PackageManager packageManager = mContext.getPackageManager();
//                            Intent intent = packageManager.getLaunchIntentForPackage(currentRunningApp.getAppid());
//                            if (intent != null) {
//                                mContext.startActivity(intent);
//                            }
//                        }
                    }
                    setHomeView(false);
                }
            });
        }
        rvApp.setAdapter(appHomeAdapter);


        int currentVolume = getAudioManager().getStreamVolume(AudioManager.STREAM_MUSIC);
        //媒体音量 STREAM_MUSIC    STREAM_RING 铃声音量
        mMaxVolume = getAudioManager().getStreamMaxVolume(AudioManager.STREAM_MUSIC);

        System.out.println("ddddddddddddddddddddddd  currentVolume  : "+currentVolume);
        setVolume(currentVolume);


//        if(!SystemUtils.isForeground(mContext,mContext.getPackageName())){
//            ivSet.setVisibility(View.GONE);
//            ivHome.setVisibility(View.VISIBLE);
//        }else {
//            ivSet.setVisibility(View.VISIBLE);
//            ivHome.setVisibility(View.GONE);
//        }

        showStartBtn(MotionDataUtils.getInstance().isRun());

        tvSpeed.setOnClickListener(this);
        tvSlop.setOnClickListener(this);
        tvStop.setOnClickListener(this);
        tvPause.setOnClickListener(this);
        ivHome.setOnClickListener(this);
        ivHome1.setOnClickListener(this);
        ivSet.setOnClickListener(this);
        ivBack.setOnClickListener(this);
        ivVolume.setOnClickListener(this);
        ivLuminance.setOnClickListener(this);
        tvStart.setOnClickListener(this);
        tvSetGoal.setOnClickListener(this);
        ivApk.setOnClickListener(this);
        ivApk1.setOnClickListener(this);
        ivSpeedReduce.setOnClickListener(this);
        ivSpeedAdd.setOnClickListener(this);
        ivSlopAdd.setOnClickListener(this);
        ivSlopReduce.setOnClickListener(this);

        ivSpeedReduce.setOnTouchListener(this);
        ivSpeedReduce.setOnLongClickListener(this);
        ivSpeedAdd.setOnTouchListener(this);
        ivSpeedAdd.setOnLongClickListener(this);

        ivSlopReduce.setOnTouchListener(this);
        ivSlopReduce.setOnLongClickListener(this);
        ivSlopAdd.setOnTouchListener(this);
        ivSlopAdd.setOnLongClickListener(this);



        WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams(
                WindowManager.LayoutParams.MATCH_PARENT,
                WindowManager.LayoutParams.WRAP_CONTENT,
                WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY,
                WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
                PixelFormat.TRANSLUCENT
        );

        layoutParams.gravity = Gravity.CENTER| Gravity. BOTTOM;

        System.out.println("ddddddddddddddddddddddd  isFist : "+isFist);

        if(isFist){
            isFist = false;
            windowManager.addView(inflate,layoutParams);
        }else {
            System.out.println("ddddddddddddddddddddddd  inflate : "+(inflate == null));
            inflate.setVisibility(View.VISIBLE);
        }

    }

    boolean isPlay = false;

    public void isPlayVideo(boolean isPlay){
        this.isPlay = isPlay;
    }

    public void initSlop(){
        String type;
        String unit = mContext.getString(R.string.app_km_h);
        String tip = mContext.getString(R.string.app_speed_txt);
        if(MotionDataUtils.mCurrentDeviceType.equals(DeviceTypeUtils.SPINNING)
                ||MotionDataUtils.mCurrentDeviceType.equals(DeviceTypeUtils.ROWING_MACHINE)
                ||MotionDataUtils.mCurrentDeviceType.equals(DeviceTypeUtils.ELLIPTICAL_MACHINE)){
            if(MotionDataUtils.mCurrentDeviceType.equals(DeviceTypeUtils.ROWING_MACHINE)){
                tip = mContext.getString(R.string.app_pace);
                unit = mContext.getString(R.string.app_per_500m);
            }
            type = mContext.getString(R.string.app_resistance);
        }else{
            type = mContext.getString(R.string.app_slop);
        }
        tvSlopTip.setText(type);
        tvSpeedTip.setText(tip);
        tvUnit.setText(unit);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.iv_home://返回首页
                SystemUtils.getInstance().setTopApp(mContext,mContext.getPackageName());
                break;
            case R.id.iv_home1://返回首页
//                if(SystemUtils.isForeground(mContext,mContext.getPackageName())){
//                    if(isPlay){
//                        if(BluetoothOrder.getInstance().isRun() || SerialPortManager.getInstance().isRun()){
//                            DialogViewUtils.getInstance().initView(mContext,true,DialogViewUtils.EXIT_SPORT);
//                            return;
//                        }
//                    }
//                }
                if(MotionDataUtils.getInstance().isRun()||MotionDataUtils.getInstance().isPause()){
                    DialogViewUtils.getInstance().initView(mContext,true,DialogViewUtils.EXIT_SPORT);
                    return;
                }
                Log.e("aaaaaaaaaaaaa", "ivHome");
                if(!SystemUtils.isForeground(mContext,mContext.getPackageName())){
//                    Intent intent = new Intent();
//                    ComponentName componentName = new
//                            ComponentName(mContext.getPackageName(), MainActivity.class.getName());
////                        ComponentName("com.thinkfit.ride",activityName);
//                    intent.setComponent(componentName);
//                    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
//                    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
//                    mContext.startActivity(intent);
                    SystemUtils.setTopApp(mContext,mContext.getPackageName());

                    HashMap<String, Object> map = new HashMap<>();
                    map.put(EventBusEvent.TO_MAIN,0);
                    EventBus.getDefault().post(map);

                    System.out.println("ddddddddddddddddddddddd  inflate GONE");
//                    inflate.setVisibility(View.GONE);
                    ShowSpeedViewUtils.getInstance().goneLayout();
//                    BackButtonViewUtils.getInstance().goneButton();
//                    atThirdParty(false);
                    setHomeView(false);
                }else {
                    Intent intent = new Intent(mContext,MainActivity.class);
                    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    mContext.startActivity(intent);
                }
//                BackButtonViewUtils.getInstance().closeButton();//去除控件
                ApkListViewUtils.getInstance().backHome();
                isShowTarget(false);
                break;
            case R.id.tv_start:
                if (!SerialPortManager.getInstance().isConnected()&&!BluetoothOrder.getInstance().isConnect()) {
                    ToastUtils.getInstance().show(mContext,mContext.getResources().getString(R.string.app_device_connect));
                    return;
                }
                Utils.startSports(mContext,false);
//                if(DataManager.Companion.getInstance().isLogin()){
//                    if(DeviceTypeUtils.getInstance().isTreadmill()){
//                        if(DeviceTypeUtils.connectDeviceType() == 0){
//                            BluetoothOrder.getInstance().startTreadmill();
//                        }else {
//                            SerialPortManager.getInstance().startRun();
//                        }
//                    }
////                    CountDownViewUtils.getInstance().initView(mContext,3);
//                }else {
//                    DialogViewUtils.getInstance().initView(mContext,false,DialogViewUtils.TOURIST_PATTERN);
//
//                }
//                if(DataManager.Companion.getInstance().isLogin()){
//                    DialogViewUtils.getInstance().initView(mContext,false,DialogViewUtils.SPORT_START);
//                }else {
//                    DialogViewUtils.getInstance().initView(mContext,false,DialogViewUtils.TOURIST_PATTERN);
//                }

                break;
            case R.id.tv_stop:
//                if (SerialPortManager.getInstance().isRun() || BluetoothOrder.getInstance().isRun()) {//判断是否有在运行
//                    DialogViewUtils.getInstance().initView(mContext,false,DialogViewUtils.EXIT_SPORT);
//                }
                DialogViewUtils.getInstance().initView(mContext,false,DialogViewUtils.EXIT_SPORT);
                break;
            case R.id.tv_pause:
                System.out.println("ddddddddddddddddddddddd  isPause : "+EquipmentInfoUtils.getInstance().isPause());
                if(EquipmentInfoUtils.getInstance().isPause()){
                    if(DeviceTypeUtils.connectDeviceType() == 0){
                        if(MotionDataUtils.getInstance().isPause()){
                            initSpeedSlopEnabled(true);
                            BluetoothOrder.getInstance().startTreadmill();
                        }else {
                            initSpeedSlopEnabled(false);
                            pauseDevice();
                        }
                    }else {
                        if(MotionDataUtils.getInstance().isPause()){
                            initSpeedSlopEnabled(true);
                            SerialPortManager.getInstance().reStartRun();
                        }else {
                            initSpeedSlopEnabled(false);
                            pauseDevice();
                        }
                    }

                }else {
                    DialogViewUtils.getInstance().initView(mContext,false,DialogViewUtils.EXIT_SPORT);
                    tvSetGoal.setText(mContext.getString(R.string.app_set_goal));
                    mType = 0;
                    mNum = 0;
                }
                break;
            case R.id.iv_set:
                Intent intent = new Intent(mContext, SettingNewActivity.class);
//                Intent intent = new Intent(mContext, SettingActivity.class);
//                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
//                mContext.startActivity(intent);
//                break;
            case R.id.iv_back:
                SystemUtils.getInstance().setTopApp(mContext,mContext.getPackageName());
                if(MotionDataUtils.getInstance().isRun()||MotionDataUtils.getInstance().isPause()){
                    if(SportsDataUtils.getInstance().mSportType == SportType.FREE){
                        intent = new Intent(mContext, FreeMovementNewActivity.class);
                        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                        mContext.startActivity(intent);
                    } else if(SportsDataUtils.getInstance().mSportType == SportType.VIDEO){

                    }else if(SportsDataUtils.getInstance().mSportType == SportType.LIVE){

                    }
                }

                break;
            case R.id.iv_volume:
//                rlSound.setVisibility(View.VISIBLE);
                SoundViewUtils.getInstance().initView(mContext);
                break;
            case R.id.iv_luminance:
                LuminanceViewUtils.getInstance().initView(mContext);
//                ApkListViewUtils.getInstance().initView(mContext);
                break;
            case R.id.tv_set_goal:
                SetTargetViewUtils.getInstance().initView(mContext);
//                SetTargetViewUtils.getInstance().showToast(mContext);
                break;
            case R.id.iv_apk:
            case R.id.iv_apk1:
                if(isShowApp){
                    isShowApp = false;
                    AppPopupWindow.getInstance().goneButton();
                }else {
                    isShowApp = true;
                    ArrayList<AppUtils.AppInfo> appList1 = getAppList();
                    if(appList1.size() > 0){
                        AppPopupWindow.getInstance().initView(mContext.getApplicationContext(), getAppList());
                    }else {
                        ToastUtils.getInstance().show(mContext,mContext.getResources().getString(R.string.apk_hint));
                    }
                }

                break;
            case R.id.iv_speed_reduce:
                isLongClick = false;
                resetSpeed(false);
                break;
            case R.id.iv_speed_add:
                isLongClick = false;
                resetSpeed(true);
                break;
            case R.id.iv_slop_reduce:
                isLongClick = false;
                resetSlop(false);
                break;
            case R.id.iv_slop_add:
                isLongClick = false;
                resetSlop(true);
                break;
            case R.id.tv_speed:
                RightSpeedSetView.getInstance().initView(mContext);
                break;
            case R.id.tv_slop:
                LeftSlopSetView.getInstance().initView(mContext);
                break;
        }

    }

    BigDecimal speed = null;
    @Override
    public boolean onTouch(View v, MotionEvent event) {
        int action = event.getAction();
        speed = null;
        switch (action){
            case MotionEvent.ACTION_DOWN:


                break;
            case MotionEvent.ACTION_MOVE:

                break;
            case MotionEvent.ACTION_UP:
                System.out.println("aaaaaaaaaaaaaaaaaaaaaaaaa  speed   MotionEvent.ACTION_UP");
                isLongClick = false;
                closeResetSpeedLong();
//                if(v.getId() == R.id.iv_speed_reduce || v.getId() == R.id.iv_speed_add ){
////                    if(speed == null){
////                        return true;
////                    }
//                    int slop = BluetoothOrder.getInstance().getCurrentInfo().slop;
//                    int speedInt = (int) (speedf*10);
//                    if(DeviceTypeUtils.connectDeviceType() == 0){
////                        System.out.println("aaaaaaaaaaaaaaaaaaaaaaaaa  speed : "+speed.floatValue());
//                        System.out.println("aaaaaaaaaaaaaaaaaaaaaaaaa  speed : "+speed.floatValue());
//
//                        System.out.println("aaaaaaaaaaaaaaaaaaaaaaaaa  speed   speedInt: "+speedInt);
//                        if(DeviceTypeUtils.getInstance().isTreadmill()){
//                            BluetoothOrder.getInstance().setTreadmillSpeedAndSlope(speedInt,slop);
//                        }else {
//                            BluetoothOrder.getInstance().setNowelAndSlope(speedInt,slop);
//                        }
//                    }else {
//                        System.out.println("aaaaaaaaaaaaaaaaaaaaaaaaa  speed11 : "+ speedInt);
//                        SerialPortManager.getInstance().setSpeedSlop(speedInt, slop);
//                    }
//                }
                break;
        }
        return false;
    }

    boolean isSpeed = false;
    boolean isSlop = false;

    public void isSpeed(boolean b){
        isSpeed = b;
    }
    public void isSlop(boolean b){
        isSlop = b;
    }

    @Override
    public boolean onLongClick(View v) {
        isLongClick = true;
        switch (v.getId()){
            case R.id.iv_speed_reduce:
                isSpeed = true;
                resetSpeedLong(false);
                break;
            case R.id.iv_speed_add:
                isSpeed = true;
                resetSpeedLong(true);
                break;
            case R.id.iv_slop_reduce:
                isSlop = true;
                resetSlopLong(false);
                break;
            case R.id.iv_slop_add:
                isSlop = true;
                resetSlopLong(true);
                break;
        }
        return false;
    }
    Disposable resetSpeedLongDisposable;
    float speedf;
    int slopItem = 1;
    int speedInt;
    public void resetSpeedLong(boolean isAdd){
        closeResetSpeedLong();
        String textById = tvSpeed.getText().toString().trim();
        speed = new BigDecimal(textById);
        speedf = speed.floatValue();
        Observable.interval(400, TimeUnit.MILLISECONDS)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<Long>() {
                    @Override
                    public void onSubscribe(Disposable d) {
                        resetSpeedLongDisposable = d;
                    }

                    @Override
                    public void onNext(Long aLong) {

                        if (isAdd) {
                            if(speedf >= EquipmentInfoUtils.getInstance().getResistance()){
                                speedf = (EquipmentInfoUtils.getInstance().getResistance()/10f);

                            }else {
//                                tvSpeed.setText((speedf += 0.1f)+"");
                                speedf += 0.1f;
//                                speed = speed.add(new BigDecimal("0.1"));
                            }
                        } else {
                            if(speedf <= 1.0f){
//                                tvSpeed.setText("1.0");
                                speedf = 1.0f;
                            }else {
//                                tvSpeed.setText((speedf -= 0.1f)+"");
                                speedf -= 0.1f;
//                                speed = speed.subtract(new BigDecimal("0.1"));
                            }

                        }
                        tvSpeed.setText(Utils.getNewFloat(speedf));
                        if(aLong%4L == 0){
                            speedInt = (int) (speedf*10);
                            setSpeed(speedInt);
                        }

                    }

                    @Override
                    public void onError(Throwable e) {
                        closeResetSpeedLong();
                    }

                    @Override
                    public void onComplete() {
                        closeResetSpeedLong();
                    }
                });
    }

    public void resetSlopLong(boolean isAdd){
        closeResetSpeedLong();
        String textById = tvSlop.getText().toString().trim();
        BigDecimal slop = new BigDecimal(textById);
        slopItem = slop.intValue();
        Observable.interval(400, TimeUnit.MILLISECONDS)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<Long>() {
                    @Override
                    public void onSubscribe(Disposable d) {
                        resetSpeedLongDisposable = d;
                    }

                    @Override
                    public void onNext(Long aLong) {
                        if (isAdd) {
                            if(slopItem >= EquipmentInfoUtils.getInstance().getSlop()){
                                slopItem = EquipmentInfoUtils.getInstance().getSlop();

                            }else {
//                                tvSpeed.setText((speedf += 0.1f)+"");
                                slopItem += 1;
//                                speed = speed.add(new BigDecimal("0.1"));
                            }
                        } else {
                            if(slopItem <= 1){
//                                tvSpeed.setText("1.0");
                                slopItem = 1;
                            }else {
//                                tvSpeed.setText((speedf -= 0.1f)+"");
                                slopItem -= 1;
//                                speed = speed.subtract(new BigDecimal("0.1"));
                            }

                        }
                        if(aLong%4L == 0){
                            setSlop(slopItem);
                        }
                        tvSlop.setText(slopItem+"");

                    }

                    @Override
                    public void onError(Throwable e) {
                        closeResetSpeedLong();
                    }

                    @Override
                    public void onComplete() {
                        closeResetSpeedLong();
                    }
                });
    }

    public void closeResetSpeedLong(){
        if(resetSpeedLongDisposable != null){
            resetSpeedLongDisposable.dispose();
            resetSpeedLongDisposable = null;
        }
    }


    public void setInfo(SerialPortManager.CurrentInfo info){
        if(inflate == null){
            return;
        }
        System.out.println("aaaaaaaaaaaaaaaaaaaaaa   info : "+info.toString());
        System.out.println("aaaaaaaaaaaaaaaaaaaaaa   isLongClick :  "+ isLongClick);
        initSlop();
        if(MotionDataUtils.mCurrentDeviceType.equals(DeviceTypeUtils.TREADMILL)
                ||MotionDataUtils.mCurrentDeviceType.equals(DeviceTypeUtils.SPINNING)
                ||MotionDataUtils.mCurrentDeviceType.equals(DeviceTypeUtils.ELLIPTICAL_MACHINE)){
            if(MotionDataUtils.mCurrentDeviceType.equals(DeviceTypeUtils.TREADMILL)){
                if(!isLongClick){
                    if(!isSpeed){
                        tvSpeed.setText(Utils.getNewFloat(info.speed*0.1f));
                    }else {
                        if(speedInt == info.speed){
                            isSpeed = false;
                        }else {
                            setSpeed(speedInt);
                        }
                    }
                    isSlop(info);
                }
            }else {
                tvSpeed.setText(Utils.getNewFloat(info.speed*0.01f));
                isSlop(info);
            }
        }else if(MotionDataUtils.mCurrentDeviceType.equals(DeviceTypeUtils.ROWING_MACHINE)){
            String text = "";
            if (info.speed <= 0f) {
                text = "00:00";
            }else {
                int time = (int) (1800/(info.speed * 0.01f));  //计算好了配速   //((info.time == 0 || info.distance < 10) ? 0 : (int) (500 / (info.distance * 1.0f / info.time) + 0.5f));//计算500需要多少秒
                int hour = time / 3600;
                int minute = (time / 60) % 60;
                int second = time % 60;
                if (hour > 0) {
                    text = BaseUtils.StaticParams.getNewText(hour) + ":"
                            + BaseUtils.StaticParams.getNewText(minute) + ":"
                            + BaseUtils.StaticParams.getNewText(second);
                } else {
                    text = BaseUtils.StaticParams.getNewText(minute) + ":"
                            + BaseUtils.StaticParams.getNewText(second);
                }
            }
            tvSpeed.setText(text);
            isSlop(info);
//                    text = Utils.getNewFloat(info.speed*0.01f);
        }


        initEnabled();
    }

    public void isSlop(SerialPortManager.CurrentInfo info){
        if(!isSlop){
            tvSlop.setText(String.valueOf(info.slop));
        }else {
            if(slopItem == info.slop){
                isSlop = false;
            }else {
                setSlop(slopItem);
            }
        }
    }

    /**
     * 设置速度
     * @param isAdd 判断是否是增加
     */
    private void resetSpeed(boolean isAdd) {
        isSpeed = true;
        String textById = tvSpeed.getText().toString().trim();
        if(textById.length()>=5){
            return;
        }
        BigDecimal speed = new BigDecimal(textById);
        if (isAdd) {
            speed = speed.add(new BigDecimal("0.1"));
            speedf = speed.floatValue();

            if(speedf >= EquipmentInfoUtils.getInstance().getResistance()/10){
                speedf = EquipmentInfoUtils.getInstance().getResistance()/10f;
            }
        } else {
            speed = speed.subtract(new BigDecimal("0.1"));
            speedf = speed.floatValue();
            if(speedf <= 1f){
                speedf = 1;
            }
        }
        if (speed.compareTo(BigDecimal.ZERO) < 0) {
            return;
        }
        speedInt = (int) (speedf*10f);
        tvSpeed.setText(Utils.getNewFloat(speedf));
//        int slop = BluetoothOrder.getInstance().getCurrentInfo().slop;
//        if(isLongClick){
//            if(DeviceTypeUtils.connectDeviceType() == 0){
//                System.out.println("aaaaaaaaaaaaaaaaaaaaaaaaa  speed : "+speedf);
//                speedInt = (int) (speedf*10);
//                System.out.println("aaaaaaaaaaaaaaaaaaaaaaaaa  speed   speedInt: "+speedInt);
//                if(DeviceTypeUtils.getInstance().isTreadmill()){
//                    BluetoothOrder.getInstance().setTreadmillSpeedAndSlope(speedInt,slop);
//                }else {
//                    BluetoothOrder.getInstance().setNowelAndSlope(speedInt,slop);
//                }
//            }else {
//                System.out.println("aaaaaaaaaaaaaaaaaaaaaaaaa  speed111 : "+speed.multiply(BigDecimal.TEN).intValue());
//                SerialPortManager.getInstance().setSpeedSlop(speed.multiply(BigDecimal.TEN).intValue(), slop);
//            }
//        }else {
//            speedInt = (int) (speed.floatValue()*10);
//            if(DeviceTypeUtils.connectDeviceType() == 0){
//                System.out.println("aaaaaaaaaaaaaaaaaaaaaaaaa  speed : "+speed.floatValue());
//                System.out.println("aaaaaaaaaaaaaaaaaaaaaaaaa  speed   speedInt: "+speedInt);
//                if(DeviceTypeUtils.getInstance().isTreadmill()){
//                    BluetoothOrder.getInstance().setTreadmillSpeedAndSlope(speedInt,slop);
//                }else {
//                    BluetoothOrder.getInstance().setNowelAndSlope(speedInt,slop);
//                }
//            }else {
//                System.out.println("aaaaaaaaaaaaaaaaaaaaaaaaa  speed1111 : "+speed.multiply(BigDecimal.TEN).intValue());
//                SerialPortManager.getInstance().setSpeedSlop(speed.multiply(BigDecimal.TEN).intValue(), slop);
//            }
//        }
        isLongClick = false;

    }
    private void setSpeed(int speed){
        int slop = MotionDataUtils.getInstance().getCurrentInfo().slop;
        if(DeviceTypeUtils.connectDeviceType() == 0){
            System.out.println("aaaaaaaaaaaaaaaaaaaaaaaaa  speed : "+speed);
            System.out.println("aaaaaaaaaaaaaaaaaaaaaaaaa  speed   speedInt: "+speed);
            if(DeviceTypeUtils.getInstance().isTreadmill()){
                BluetoothOrder.getInstance().setTreadmillSpeedAndSlope(speed,slop);
            }else {
                BluetoothOrder.getInstance().setNowelAndSlope(speed,slop);
            }
        }else {
            System.out.println("aaaaaaaaaaaaaaaaaaaaaaaaa  speed11111 : "+speed);
            SerialPortManager.getInstance().setSpeedSlop(speed, slop);
        }
    }

    /**
     * 设置坡度
     * @param isAdd 判断是否是增加
     */
    private void resetSlop(boolean isAdd) {
        isSlop = true;
        String trim = tvSlop.getText().toString().trim();
        BigDecimal value = new BigDecimal(trim);
        if (isAdd) {
            value = value.add(new BigDecimal("1"));
            slopItem = value.intValue();
            if(slopItem >= EquipmentInfoUtils.getInstance().getSlop()){
                slopItem = EquipmentInfoUtils.getInstance().getSlop();
            }
        } else {
            value = value.subtract(new BigDecimal("1"));
            slopItem = value.intValue();
            if(DeviceTypeUtils.getDeviceType() == 2){
                if(slopItem <= 0){
                    slopItem = 0;
                }
            }else {
                if(slopItem <= 1){
                    slopItem = 1;
                }
            }

        }
//        if (value.compareTo(BigDecimal.ZERO) < 0 || slopItem >= EquipmentInfoUtils.getInstance().getSlop()) {
//            return;
//        }
        int speed = MotionDataUtils.getInstance().getCurrentInfo().speed;
        System.out.println("aaaaaaaaaaaaaaaaaaaaaaaaa  slop : "+ slopItem);
//        int slopNum = 0;
//        if(isLongClick){
//            slopNum = slopItem;
//        }else {
//            slopNum = value.intValue();
//        }
        tvSlop.setText(slopItem+"");
//        if(!isLongClick){
//            slopItem =  value.intValue();
//        }

//        if(DeviceTypeUtils.connectDeviceType() == 0){
//            if (BluetoothOrder.mCurrentDeviceType.equals(DeviceTypeUtils.TREADMILL)){
//                if (value.intValue() < 0) {
//                    return;
//                }
//                BluetoothOrder.getInstance().setTreadmillSpeedAndSlope(speed,slopItem);
//
//            }else {
//
//                if (value.intValue() < 0 || value.intValue() > 32) {
//                    return;
//                }
//                int slop = BluetoothOrder.getInstance().getCurrentInfo().slop;
//                BluetoothOrder.getInstance().setNowelAndSlope(slopItem, slop);
//            }
//        }else {
//            if (SerialPortManager.mCurrentDeviceType == DeviceType.RUNNING_MACHINE) {
//                if (value.intValue() < 0) {
//                    return;
//                }
//                System.out.println("aaaaaaaaaaaaaaaaaaaaaaaaa  slop :  slopItem : "+slopItem+"   speed : "+speed);
//                SerialPortManager.getInstance().setSpeedSlop(speed, slopItem);
//            } else {
//                if (value.intValue() < 0 || value.intValue() > 32) {
//                    return;
//                }
//                System.out.println("aaaaaaaaaaaaaaaaaaaaaaaaa  slop :  slopNum : "+slopItem);
//                int slop = SerialPortManager.getInstance().getCurrentInfo().slop;
//                SerialPortManager.getInstance().setResistanceSlop(slopItem, slop);
//            }
//        }
        isLongClick = false;
    }

    public void setSlop(int slop){
        int speed = MotionDataUtils.getInstance().getCurrentInfo().speed;
        if(DeviceTypeUtils.connectDeviceType() == 0){
            if (MotionDataUtils.mCurrentDeviceType.equals(DeviceTypeUtils.TREADMILL)){
                if (slop < 0) {
                    return;
                }
                BluetoothOrder.getInstance().setTreadmillSpeedAndSlope(speed,slop);

            }else {

                if (slop < 0 || slop > 32) {
                    return;
                }
                int slopNum = MotionDataUtils.getInstance().getCurrentInfo().slop;
                BluetoothOrder.getInstance().setNowelAndSlope(slop, slopNum);
            }
        }else {
            if (MotionDataUtils.mCurrentDeviceType.equals(DeviceTypeUtils.TREADMILL)) {
                if (slop < 0) {
                    return;
                }
                System.out.println("ddddddddddddddddddddddd    sendMsg1111 :  slop : "+slop+"   speed : "+speed);
                SerialPortManager.getInstance().setSpeedSlop(speed, slop);
            } else {
                if (slop <= 0 || slop > 32) {
                    return;
                }

                int slopNum = MotionDataUtils.getInstance().getCurrentInfo().slop;
                System.out.println("ddddddddddddddddddddddd    sendMsg2222 :  slop : "+slop+"  slopNum : "+slopNum);
                SerialPortManager.getInstance().setResistanceSlop(slop, slopNum);
            }
        }
    }

    public void click(boolean b){
        if(inflate != null){
            ivSpeedAdd.setEnabled(b);
            ivSpeedReduce.setEnabled(b);
            ivSlopAdd.setEnabled(b);
            ivSlopReduce.setEnabled(b);
            tvStop.setEnabled(b);
            tvPause.setEnabled(b);
        }
    }

    public void stopInitView(){
        if(inflate != null){
            tvSetGoal.setText(mContext.getString(R.string.app_set_goal));
            mType = 0;
            mNum = 0;
            speedf = 0f;
            speedInt = 0;
            slopItem = 0;
            isLongClick = false;
            showStartBtn(false);
            initSpeedSlopEnabled(true);
        }

    }

    public void pauseInitView(){
        tvSpeed.setText("0.0");
        tvSlop.setText("0");
    }
    boolean isEnabled = true;
    public void setEnabled(boolean b){
        isEnabled = b;
    }

    public void initEnabled(boolean b){
        isEnabled = b;
        initEnabled();
    }

    public void initSpeedSlopEnabled(boolean b){
        if(inflate != null){
            ivSpeedAdd.setEnabled(b);
            ivSpeedReduce.setEnabled(b);
            ivSlopAdd.setEnabled(b);
            ivSlopReduce.setEnabled(b);
        }
    }

    public void initEnabled(){
        if(inflate != null){
            ivSpeedAdd.setEnabled(isEnabled);
            ivSpeedReduce.setEnabled(isEnabled);
            ivSlopAdd.setEnabled(isEnabled);
            ivSlopReduce.setEnabled(isEnabled);
            tvPause.setEnabled(isEnabled);
            tvStop.setEnabled(isEnabled);
        }
    }

    public void setVolume(int volume){
        if(inflate != null){
            SoundIconUtils.getInstance().setVolume(ivVolume,volume);
        }
//        if(volume<=0){
//            ivVolume.setImageResource(R.drawable.img_main_volume_min_dw);
////            ivVolume.setImageResource(R.drawable.img_main_volume_min);4
//        }else if(volume<10){
//            ivVolume.setImageResource(R.drawable.img_main_volume_mid_dw);
////            ivVolume.setImageResource(R.drawable.img_main_volume_mid);
//        }else if(volume<15){
//            ivVolume.setImageResource(R.drawable.img_main_volume_max_dw);
////            ivVolume.setImageResource(R.drawable.img_main_volume_max);
//        }
    }
    ArrayList<ApplicationBean> appList = new ArrayList<>();
    public void initAppList(ArrayList<ApplicationBean> list){
        appList.clear();
        Observable.create(new ObservableOnSubscribe<List<ApplicationBean>>() {
            @Override
            public void subscribe(ObservableEmitter<List<ApplicationBean>> emitter) throws Exception {
                PackageManager packageManager = mContext.getPackageManager();
                // 获取已安装的app信息
                List<PackageInfo> pkgInfos = packageManager.getInstalledPackages(0);
                if (pkgInfos != null) {
                    for (ApplicationBean bean : list) {
                        for (PackageInfo info : pkgInfos) {
                            //  Log.e("aaaaaaaaaa", info.packageName+", "+info.applicationInfo.loadLabel(packageManager).toString());
                            if (bean.getAppid().equals(info.packageName)) {
//                        bean.setInstallStatus(2);
                                appList.add(bean);
                                break;
                            }
                        }
                    }
                }
                emitter.onNext(appList);
            }
        }).subscribe(new Observer<List<ApplicationBean>>() {
            @Override
            public void onSubscribe(Disposable d) {

            }

            @Override
            public void onNext(List<ApplicationBean> applicationBeans) {
                appHomeAdapter.setNewInstance(appList);
            }

            @Override
            public void onError(Throwable e) {

            }

            @Override
            public void onComplete() {

            }
        });
//        PackageManager packageManager = mContext.getPackageManager();
//        // 获取已安装的app信息
//        List<PackageInfo> pkgInfos = packageManager.getInstalledPackages(0);
//        if (pkgInfos != null) {
//            for (ApplicationBean bean : list) {
//                for (PackageInfo info : pkgInfos) {
//                    //  Log.e("aaaaaaaaaa", info.packageName+", "+info.applicationInfo.loadLabel(packageManager).toString());
//                    if (bean.getAppid().equals(info.packageName)) {
////                        bean.setInstallStatus(2);
//                        appList.add(bean);
//                        break;
//                    }
//                }
//            }
//        }
//        appHomeAdapter.setNewInstance(appList);
    }

    public void setTarget(int type,int num){
        if(inflate == null){
            return;
        }
        mType = type;
        mNum = num;
        System.out.println("aaaaaaaaaaaaaaaaaaaaaaaaa  mType : "+mType+"   mNum  : "+mNum);
        if(num == 0){
            tvSetGoal.setText(mContext.getString(R.string.app_set_goal));
        }else {
            tvSetGoal.setText(targetType(type,num));
        }
    }

    public ArrayList<Integer> getTarget(){
        ArrayList<Integer> objects = new ArrayList<>();
        objects.add(mType);
        objects.add(mNum);
        return objects;
    }

    public String targetType(int type,int num){
        String str = null;
        if(type == 1){
            str = mContext.getString(R.string.app_target_xxx_minutes,num+"");
        }else if(type == 2){
            str = mContext.getString(R.string.app_target_xxx_km,num+"");
        }else {
            str = mContext.getString(R.string.app_target_xxx_kcal,num+"");
        }
        return str;
    }

    public ArrayList<AppUtils.AppInfo> getAppList(){
        ArrayList<AppUtils.AppInfo> list1 = new ArrayList<>();
        PackageManager pm = mContext.getPackageManager();
        List<PackageInfo> packages = pm.getInstalledPackages(0);
        int size = packages.size();
        for (int i = 0; i < size; i++) {
            PackageInfo packageInfo = packages.get(i);
            if ((packageInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) > 0 ||
                    packageInfo.packageName.equals(mContext.getPackageName())) {
                continue;
            }
            list1.add(new AppUtils.AppInfo(
                    packageInfo.packageName,
                    packageInfo.applicationInfo.loadLabel(pm).toString(),
                    packageInfo.applicationInfo.loadIcon(pm),
                    "",
                    packageInfo.versionName,
                    packageInfo.versionCode,
                    false
            ));
        }
        return list1;
    }

    private AudioManager getAudioManager() {
        if (mAudioManager == null) {
            mAudioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
        }
        return mAudioManager;
    }

    public void pauseDevice(){
        if(!(SerialPortManager.getInstance().isConnected() || BluetoothOrder.getInstance().isConnect())){
            System.out.println("ddddddddddddddddddddddd   未连接设备");
            return;
        }
        if(DeviceTypeUtils.connectDeviceType() == 0){//判断连接类型
            BluetoothOrder.getInstance().closeRxJavaClone();
            BluetoothOrder.getInstance().closeTreadmillStateDisposable();
            if(EquipmentInfoUtils.getInstance().isPause()){
                System.out.println("ddddddddddddddddddddddd   蓝牙通知设备暂停");
                if(DeviceTypeUtils.getInstance().isTreadmill()){
                    BluetoothOrder.getInstance().pauseTreadmill();
                }else {
                    BluetoothOrder.getInstance().bluetoothOrderWrite(BluetoothOrder.EQUIPMENT_PAUSE);
                }

            }

        }else {
            System.out.println("ddddddddddddddddddddddd   串口通知设备暂停");
            SerialPortManager.getInstance().pauseRun();
        }
    }

    public void invaliView(){
        if(inflate != null){
            isFist = true;
            windowManager.removeView(inflate);
            inflate = null;
        }
    }


    public void showStartBtn(boolean isRun) {
        if(inflate == null){
            return;
        }
        this.isRun = isRun;
        if (isRun) {
            clRunning.setVisibility(View.VISIBLE);
            clBottom.setVisibility(View.INVISIBLE);
            if(!MotionDataUtils.getInstance().isPause()){
//                tvPause.setBackgroundResource(R.drawable.img_main_pause);
                tvPause.setText(mContext.getString(R.string.app_pause));
            }
            if(DeviceTypeUtils.getDeviceType() == 2){
                ivSpeedReduce.setVisibility(View.VISIBLE);
                ivSpeedAdd.setVisibility(View.VISIBLE);
            }else {
                ivSpeedReduce.setVisibility(View.GONE);
                ivSpeedAdd.setVisibility(View.GONE);

            }

        } else {
            System.out.println("aaaaaaaaaaaaaaaaaaaaaa   isRun1 : "+isRun);
            if(MotionDataUtils.getInstance().isPause()){
//                tvPause.setBackgroundResource(R.drawable.img_main_start);
                tvPause.setText(mContext.getString(R.string.app_cont));
            }else {
//                if(DataManager.Companion.getInstance().isLogin()){
//                    LoadViewUtils.getInstance().initView(mContext,R.string.app_sport_report_generating_exercise_report);
//                }
                clRunning.setVisibility(View.INVISIBLE);
                clBottom.setVisibility(View.VISIBLE);
            }
        }
    }



    public void isMain(boolean isMain){
        HashMap<String, Object> mMap = new HashMap<>();
        mMap.put(EventBusEvent.SET_HOME_OR_SET, isMain);
        EventBus.getDefault().post(mMap);
    }
    public void setIsShowApp(boolean b){
        isShowApp = b;
    }

    public void setHomeView(boolean b){
        if(inflate == null){
            return;
        }
        if(b){
            ivSet.setVisibility(View.VISIBLE);
            ivHome.setVisibility(View.INVISIBLE);
            ivBack.setVisibility(View.VISIBLE);
            ivHome1.setVisibility(View.INVISIBLE);
//            rvApp.setVisibility(View.GONE);
        }else {
            ivSet.setVisibility(View.INVISIBLE);
            ivHome.setVisibility(View.VISIBLE);
            ivBack.setVisibility(View.INVISIBLE);
            ivHome1.setVisibility(View.VISIBLE);
//            rvApp.setVisibility(View.VISIBLE);
        }

    }

    public void atThirdParty(boolean b){
        if(inflate == null){
            return;
        }
        if(b){
            ivSet.setVisibility(View.GONE);
            ivHome.setVisibility(View.VISIBLE);
            ivBack.setVisibility(View.VISIBLE);
            ivHome1.setVisibility(View.GONE);
            rvApp.setVisibility(View.VISIBLE);
        }else {
            ivSet.setVisibility(View.VISIBLE);
            ivHome.setVisibility(View.GONE);
            ivBack.setVisibility(View.INVISIBLE);
            ivHome1.setVisibility(View.VISIBLE);
            rvApp.setVisibility(View.GONE);
        }
    }

    public void transparencyAnimation(Context context,boolean isShow){
        AlphaAnimation alphaAnimation ;
        if(isShow){
            initView(context);
            alphaAnimation = new AlphaAnimation(0f, 1f);
        }else {
            alphaAnimation = new AlphaAnimation(1f, 0f);
            ApkListViewUtils.getInstance().goneButton();
        }
        alphaAnimation.setDuration(500);
        alphaAnimation.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {

            }

            @Override
            public void onAnimationEnd(Animation animation) {
                if(isShow){

                }else {
                    goneLayout();

                }
            }

            @Override
            public void onAnimationRepeat(Animation animation) {

            }
        });
        clRunning.startAnimation(alphaAnimation);
//        if(isRun){
//            clRunning.startAnimation(alphaAnimation);
//        }else {
////            clBottom.startAnimation(alphaAnimation);
//        }
    }

    public void isShowTarget(boolean isShow){
        if(isShow){
            tvSetGoal.setVisibility(View.INVISIBLE);
        }else {
            if(DataManager.Companion.getInstance().getMainStyle() == ThemeUtils.THEME_MAIN){
                tvSetGoal.setVisibility(View.VISIBLE);
            }

        }
    }

    public void goneLayout(){
        if(windowManager != null){
            if(inflate != null){
                inflate.setVisibility(View.GONE);
                ShowSpeedViewUtils.getInstance().goneLayout();
            }
        }

    }
    public void visibleLayout(){
        if(windowManager != null){
            if(inflate != null){
                inflate.setVisibility(View.VISIBLE);
                ShowSpeedViewUtils.getInstance().goneLayout();
            }
        }

    }



}
